package jeulin.mobile.BDD;

import java.util.ArrayList;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

public class Copro {

	private int idCopro;
	private String Nom_Copro;
	
	public Copro(){}
	
	public static ArrayList<Copro> getCoprosByVille(SQLiteDatabase db, int idVille){
		ArrayList<Copro> copros = new ArrayList<Copro>();
		
		Cursor c = db.rawQuery("SELECT DISTINCT IDCopro, Nom_Copro "+
				" FROM villes v JOIN adresses a ON v.IDVille = a.VilleID JOIN copros c ON a.CoproID = c.IDCopro"+
				" WHERE a.VilleID = "+idVille, null);
		copros = cursorToInfos(c, copros);
		return copros;
	}
	
	/*
	 * cursor
	 */
	private static ArrayList<Copro> cursorToInfos(Cursor c, ArrayList<Copro> copros) {
		if (c.getCount() != 0){
			c.moveToFirst();
			do{
				Copro cop = new Copro();
				cop.setIdCopro(c.getInt(0));
				cop.setNomCopro(c.getString(1));
				copros.add(cop);
			}while(c.moveToNext());
		}
		c.close();
		return copros;
	}

	public int getIdCopro() {
		return idCopro;
	}

	public String getNomCopro() {
		return Nom_Copro;
	}

	public void setIdCopro(int idCopro) {
		this.idCopro = idCopro;
	}

	public void setNomCopro(String nom_Copro) {
		Nom_Copro = nom_Copro;
	}
}
